package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.context.BaseContext;
import com.example.entity.Category;
import com.example.mapper.CategoryMapping;
import com.example.service.ICategoryService;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapping, Category> implements ICategoryService {

    /*
    * 添加分类
    * @param category
    * @return
    * */
    @Override
    public void addCategory(Category category) {
        String name = category.getName();
        // 判断分类是否已经存在
        Long count = lambdaQuery()
                .eq(Category::getName, name)
                .count();
        if (count == 0) {
            Category category1 = Category.builder()
                    .name(name)
                    .build();
            save(category1);
        }
        else {
            return;
        }
    }

}
